<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加智能家居</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">

        <div class="layui-form-item">
            <label class="layui-form-label">设备名称：</label>
            <div class="layui-input-block">
                <select name="name" lay-verify="required">
                    <option value=""></option>
                    <option value="智能液晶AI电视">智能液晶AI电视</option>
                    <option value="动感照明灯">动感照明灯</option>
                    <option value="78K超级摄像头">78K超级摄像头</option>
                    <option value="超级Ai暖床女朋友">超级Ai暖床女朋友</option>
                    <option value="小度AI">小度AI</option>
                    <option value="感应断电器">感应断电器</option>
                </select>
            </div>
        </div>

    <div class="layui-form-item">
        <label class="layui-form-label">设备类型：</label>
        <div class="layui-input-block">
            <select name="device_flag" lay-verify="required">
                <option value=""></option>
                <option value="主机网关">主机网关</option>
                <option value="智能照明">智能照明</option>
                <option value="安防报警">安防报警</option>
                <option value="家电控制">家电控制</option>
                <option value="窗帘窗户">窗帘窗户</option>
                <option value="智能门锁">智能门锁</option>
                <option value="视频监控">视频监控</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">房源信息：</label>
        <select name="house_id" id="fids" lay-verify="required">

        </select>
    </div>







    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">新增智能家居</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    var from,$;
    layui.use(['form','laydate','layarea'], function () {
         form = layui.form,
            layer = layui.layer,
            laydate=layui.laydate,
            layarea = layui.layarea,
            $ = layui.$;

        loadGids();
        //渲染日期框
        laydate.render({
            elem: '#date1' //指定元素
        });
        //渲染日期框
        laydate.render({
            elem: '#date2' //指定元素
        });
        //实现省市县三级联动
        var home="";
        layarea.render({
            elem: '#area-picker',
            change: function (res) {
                //选择结果
                home=res.province+res.city+res.county;
            }
        });
        //监听提交，实现数据新增
        form.on('submit(saveBtn)', function (data) {
            //请求接口  Ajax
            var d=data.field;
            d.home=home;
            $.post("/api/aihome/save.do",d,function (res){
                if(res.code==200){
                    layer.msg("添加成功！");
                    // 关闭弹出层
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                }else {
                    layer.msg("亲，新增人员失败！");
                }
            })
            return false;
        });
    });

    function loadGids(){
        //请求接口  Ajax
        // 租房
        $.get("/api/house/allhouse.do",(res)=>{
            if(res.code==200){
                console.log(res.data)
                $("#fids").html("");
                //遍历
                for(var i in res.data){
                    $("#fids").append("<option value='"+res.data[i].id+"'>"+"房子类型："+res.data[i].houseType+"，"+"房子地址："+res.data[i].houseSite+"</option>");
                }
                form.render('select'); //渲染 select 选择框
            }
        })
    }
</script>
</body>
</html>